﻿using _8Group.MES.ClientManagement;
using _8Group.MES.ISongService.MdItemType.DTO;
using _8Group.MES.ISongService.MdWorkshop.DTO;
using _8Group.MES.ISongService.ProWorkorder.DTO;
using _8Group.MES.ISongService.WmBarCode.DTO;
using _8Group.MES.ISongService.WmItemRecpt.DTO;
using _8Group.MES.ISongService.WmOutsourceRecpt.DTO;
using _8Group.MES.ISongService.WMProductRecpt.DTO;
using _8Group.MES.MeasuringUnit;
using _8Group.MES.Meng_Service;
using _8Group.MES.Model.WM仓储管理;
using _8Group.MES.Service;
using _8Group.MES.SongService;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace _8Group.MES.Web.Controllers
{
    /// <summary>
    /// 宋恒漳控制器(个人任务的所有视图和方法都写在该控制器里)
    /// </summary>
    public class SongController : Controller
    {
        #region 注入
        private readonly MdItemTypeService _mdItemTypeService;
        private readonly MdWorkshopService _mdWorkshopService;
        private readonly WmItemRecptService _wmItemRecptService;
        private readonly WmProductRecptService _wmProductRecptService;
        private readonly WmBarCodeService _wmBarCodeService;
        private readonly WmItemRecptLineService _wmItemRecptLineService;
        private readonly WmOutsourceRecptService _wmOutsourceRecptService;
        private readonly ProWorkorderService _proWorkorderService;
        public SongController(MdItemTypeService mdItemTypeService, MdWorkshopService mdWorkshopService, WmItemRecptService wmItemRecptService, WmProductRecptService wmProductRecptService, WmBarCodeService wmBarCodeService, WmItemRecptLineService wmItemRecptLineService, WmOutsourceRecptService wmOutsourceRecptService, ProWorkorderService proWorkorderService)
        {
            _mdItemTypeService = mdItemTypeService;
            _mdWorkshopService = mdWorkshopService;
            _wmItemRecptService = wmItemRecptService;
            _wmProductRecptService = wmProductRecptService;
            _wmBarCodeService = wmBarCodeService;
            _wmItemRecptLineService = wmItemRecptLineService;
            _wmOutsourceRecptService = wmOutsourceRecptService;
            _proWorkorderService = proWorkorderService;
        }

        public IActionResult Index()
        {
            return View();
        }

        #endregion

        #region 物料产品分类
        /// <summary>
        /// 添加页面
        /// </summary>
        /// <returns></returns>
        public IActionResult AddMdItemType()
        {
            return View();
        }

        /// <summary>
        /// 修改页面
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdMdItemType()
        {
            return View();
        }

        /// <summary>
        /// 物料产品分类树
        /// </summary>
        /// <param name="requestMd"></param>
        /// <returns></returns>
        public async Task<object> MaterialProductTypeTree(RequestMdItemTypeDTO requestMd)
        {
            var result = await _mdItemTypeService.GetMdItemTypeListAsync(requestMd);
            return result;
        }

        /// <summary>
        /// 新增 物料产品分类
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<int> AddMdItemTypeAsyncs(AddMdItemTypeDTO input)
        {
            var result = await _mdItemTypeService.AddMdItemTypeAsync(input);
            return result;
        }

        /// <summary>
        /// 更新 物料产品分类
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [ActionName("UpdMdItemTypeAsync")]
        public IActionResult UpdMdItemTypeAsync(UpdMdItemTypeDTO input)
        {
            var result = _mdItemTypeService.UpdateMdItemTypeAsync(input);
            return Ok(result);
        }

        /// <summary>
        /// 删除物料产品分类
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<bool> DeleteMdItemTypeAsyncs(int id)
        {
            var result = await _mdItemTypeService.DeleteMdItemTypeAsync(id);
            return result;
        }
        #endregion

        #region 车间管理
        /// <summary>
        /// 修改页面
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdMdIWorkshop()
        {
            return View();
        }

        /// <summary>
        /// 添加页面
        /// </summary>
        /// <returns></returns>
        public IActionResult AddMdIWorkshop()
        {
            return View();
        }

        /// <summary>
        /// 获取 MdWorkshop 列表
        /// </summary>
        /// <param name="workShopDTO"></param>
        /// <returns></returns>
        public async Task<object> GetMdWorkshopList(RequestMdWorkShopDTO workShopDTO)
        {
            var result = await _mdWorkshopService.GetMdWorkshopList(workShopDTO);
            return result;

        }

        /// <summary>
        /// 删除车间管理
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<bool> DeleteMdWorkshop(int id)
        {
            var result = await _mdWorkshopService.DeleteMdWorkshop(id);
            return result;
        }

        /// <summary>
        /// 更新车间管理
        /// </summary>
        /// <param name="mdWorkshopDTO"></param>
        /// <returns></returns>
        public async Task<bool> UpdataMdWorkshop(UpdMdIWorkshopDTO mdWorkshopDTO)
        {
            var result = await _mdWorkshopService.UpdataMdWorkshop(mdWorkshopDTO);
            return result;
        }

        /// <summary>
        /// 新增车间管理
        /// </summary>
        /// <param name="mdWorkshopDTO"></param>
        /// <returns></returns>
        public async Task<bool> AddMdWorkshop(AddMdWorkShopDTO mdWorkshopDTO)
        {
            var result = await _mdWorkshopService.AddMdWorkshop(mdWorkshopDTO);
            return result;
        }
        #endregion

        #region 采购入库
        /// <summary>
        /// 添加页面
        /// </summary>
        /// <returns></returns>
        public IActionResult AddWmItemRecpt()
        {
            return View();
        }

        /// <summary>
        /// 修改页面
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdWmItemRecpt()
        {
            return View();
        }

        /// <summary>
        /// 供应商页面
        /// </summary>
        /// <returns></returns>
        public IActionResult SupplierManagements()
        {
            return View();
        }

        /// <summary>
        /// 获取采购入库列表
        /// </summary>
        /// <param name="itemRecptDTO"></param>
        /// <returns></returns>
        public async Task<object> GetWmItemRecptList(RequestWmItemRecptDTO itemRecptDTO)
        {
            var result = await _wmItemRecptService.GetWmItemRecptListAsync(itemRecptDTO);
            return result;
        }

        /// <summary>
        /// 删除采购入库
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<bool> DeleteWmItemRecpt(int id)
        {
            var result = await _wmItemRecptService.DeleteWmItemRecptAsync(id);
            return result;
        }

        /// <summary>
        /// 新增采购入库
        /// </summary>
        /// <param name="createWmItemRecptDTO"></param> 
        /// <returns></returns>
        [HttpPost]
        public async Task<bool> AddWmItemRecpts(AddWmItemRecptDTO addWmItemRecptDTO)
        {
            var result = await _wmItemRecptService.AddWmItemRecptAsync(addWmItemRecptDTO);
            return result;
        }

        /// <summary>
        /// 修改采购入库
        /// </summary>
        /// <param name="updateWmItemRecptDTO"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<bool> UpdateWmItemRecpt(UpdateWmItemRecptDTO updateWmItemRecptDTO)
        {
            var result = await _wmItemRecptService.UpdateWmItemRecptAsync(updateWmItemRecptDTO);
            return result;
        }

        /// <summary>
        /// 更新采购入库状态
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<bool> UpdateWmItemRecptStatus(int id)
        {
            var result = await _wmItemRecptService.UpdateWmItemRecptStatusAsync(id);
            return result;
        }
        #endregion

        #region 采购入库单行表

        /// <summary>
        /// 添加页面
        /// </summary>
        /// <returns></returns>
        public IActionResult AddWmItemRecptLine()
        {
            return View();
        }

        /// <summary>
        /// 物料产品分类页面
        /// </summary>
        /// <returns></returns>
        public IActionResult MaterialProducts()
        {
            return View();
        }

        public async Task<object> GetLineList(string? code)
        {
            var result = await _wmItemRecptLineService.GetListAsync(code);
            return result;
        }


        #endregion

        #region 产品入库
        /// <summary>
        /// 添加页面
        /// </summary>
        /// <returns></returns>
        public IActionResult AddWmProductRecpt()
        {
            return View();
        }

        /// <summary>
        /// 添加生产工单产品入库页面
        /// </summary>
        /// <returns></returns>
        public IActionResult AddWmProductRecpts()
        {
            return View();
        }

        /// <summary>
        /// 修改页面
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdWmProductRecpt()
        {
            return View();
        }

        /// <summary>
        /// 获取产品入库列表
        /// </summary>
        /// <param name="productRecptDTO"></param>
        /// <returns></returns>
        public async Task<object> GetProductRecptList(RequestWmProductRecptDTO productRecptDTO)
        {
            var result = await _wmProductRecptService.GetProductRecptListAsync(productRecptDTO);
            return result;
        }

        /// <summary>
        /// 新增产品入库
        /// </summary>
        /// <param name="createWmProductRecptDTO"></param>
        /// <returns></returns>
        public async Task<bool> AddProductRecpt(AddWmProductRecptDTO createWmProductRecptDTO)
        {
            var result = await _wmProductRecptService.AddProductRecptAsync(createWmProductRecptDTO);
            return result;

        }

        /// <summary>
        /// 删除产品入库
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<bool> DeleteProductRecp(int id)
        {
            var result = await _wmProductRecptService.DeleteProductRecptAsync(id);
            return result;
        }

        /// <summary>
        /// 更新产品入库
        /// </summary>
        /// <param name="updateWmProductRecptDTO"></param>
        /// <returns></returns>
        public async Task<bool> UpdateProductRecpt(UpdateWmProductRecptDTO updateWmProductRecptDTO)
        {
            var result = await _wmProductRecptService.UpdateProductRecptAsync(updateWmProductRecptDTO);
            return result;
        }

        /// <summary>
        /// 更新产品入库状态
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<bool> UpdateProductRecptStatus(int id)
        {
            var result = await _wmProductRecptService.UpdateProductRecptStatusAsync(id);
            return result;
        }
        #endregion

        #region 赋码管理
        /// <summary>
        /// 获取条码信息
        /// </summary>
        /// <param name="barCodeDTO"></param>
        /// <returns></returns>
        public async Task<object> GetWmBarCode(RequestWmBarCodeDTO barCodeDTO)
        {
            var result = await _wmBarCodeService.GetWmBarCodeAsync(barCodeDTO);
            return result;
        }
        #endregion

        #region 外协入库
        /// <summary>
        /// 外协入库页面
        /// </summary>
        /// <returns></returns>
        public IActionResult Outsourced()
        {
            return View();
        }

        /// <summary>
        /// 外协入库页面
        /// </summary>
        /// <returns></returns>
        public IActionResult AddOutsourced()
        {
            return View();
        }

        /// <summary>
        /// 获取外协入库列表
        /// </summary>
        /// <param name="applicationDTO"></param>
        /// <returns></returns>
        public async Task<object> GetOutsourceRecptList(RequestIApplicationDTO applicationDTO)
        {
            var result = await _wmOutsourceRecptService.GetOutsourceRecptList(applicationDTO);
            return result;
        }

        /// <summary>
        /// 删除外协入库
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<bool> DeleteOutsourceRecpt(int id)
        {
            var result = await _wmOutsourceRecptService.DeleteOutsourceRecpt(id);
            return result;
        }

        /// <summary>
        ///新增外协入库
        /// </summary>
        /// <param name="wmOutsourceRecptDTO"></param>
        /// <returns></returns>
        public async Task<bool> AddOutsourceRecpt(AddWmOutsourceRecptDTO wmOutsourceRecptDTO)
        {
            var result = await _wmOutsourceRecptService.AddOutsourceRecpt(wmOutsourceRecptDTO);
            return result;
        }

        /// <summary>
        ///     更新外协入库
        /// </summary>
        /// <param name="wmOutsourceRecptDTO"></param>
        /// <returns></returns>
        public async Task<bool> UpdateOutsourceRecpt(UpdateWmOutsourceRecptDTO wmOutsourceRecptDTO)
        {
            var result = await _wmOutsourceRecptService.UpdateOutsourceRecpt(wmOutsourceRecptDTO);
            return result;
        }
        #endregion

        #region 点检保养计划
        /// <summary>
        /// 点检保养计划页面
        /// </summary>
        /// <returns></returns>
        public IActionResult InspectionPlan()
        {
            return View();
        }


        #endregion

        #region 生产工单
        /// <summary>
        /// 生产工单页面
        /// </summary>
        /// <returns></returns>
        public IActionResult ProductionOrder()
        {
            return View();
        }

        /// <summary>
        ///添加生产工单页面
        /// </summary>
        /// <returns></returns>
        public IActionResult AddProductionOrder()
        {
            return View();
        }

        /// <summary>
        ///修改生产工单页面
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdProductionOrder()
        {
            return View();
        }

        /// <summary>
        /// 获取所有工单
        /// </summary>
        /// <returns></returns>
        public async Task<object> GetProWorkorder(RequestProWorkorderDTO workorderDTO)
        {
            var result = await _proWorkorderService.GetProWorkorderAsync(workorderDTO);
            return result;
        }

        /// <summary>
        /// 添加工单
        /// </summary>
        /// <param name="workorderDTO"></param>
        /// <returns></returns>
        public async Task<bool> AddProWorkorder(AddProWorkorderDTO workorderDTO)
        {
            var result = await _proWorkorderService.AddProWorkorderAsync(workorderDTO);
            return result;
        }

        /// <summary>
        /// 删除工单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<bool> DeleteProWorkorder(int id)
        {
            var result = await _proWorkorderService.DeleteProWorkorderAsync(id);
            return result;

        }

        /// <summary>
        /// 更新工单
        /// </summary>
        /// <param name="workorderDTO"></param>
        /// <returns></returns>
        public async Task<bool> UpdateProWorkorder(UpdateProWorkorderDTO workorderDTO)
        {
            var result = await _proWorkorderService.UpdateProWorkorderAsync(workorderDTO);
            return result;
        }
        #endregion

        #region 生产报工





        #endregion
    }
}
